added construct_proccode function#457
Conversation
Signed-off-by: itsaethrr <itsaethrr@gmail.com>
Signed-off-by: itsaethrr <itsaethrr@gmail.com>
Signed-off-by: itsaethrr <itsaethrr@gmail.com>
Signed-off-by: itsaethrr <itsaethrr@gmail.com>
Signed-off-by: itsaethrr <itsaethrr@gmail.com>
Signed-off-by: itsaethrr <itsaethrr@gmail.com>
Signed-off-by: itsaethrr <itsaethrr@gmail.com>
Signed-off-by: faretek <107722825+FAReTek1@users.noreply.github.com>
|
I removed the line from the README. This still needs:
But otherwise yes. For some reason I thought I had implemented this previously, but I appreciate that people are able to build upon scratchattach.editor, as I wanted it to be cleaner that project_json_capabilities.py |
I've tested it with dummy classes and it works, but ofc you can test it and make the necessary changes :p thanks |
|
I'll try this now |
- docstring - use isinstance() not hasattr() - add support for ArgumentType instance - caching and defaulting for Argument._type and Argument.mutation
|
I've changed the code a lot. I think that isinstance() checks are a lot better than hasattr() when possible, and I've changed the docstring. And I see now that the mutation code structure is a bit of a mess because there a lot of classes which are not documented, so it is easy to get confused. I also made construct_proccode use *args, which means you can pass in as many args as you want I've also fixed a few unrelated bugs, and edited parse_proccode() so that this is a pure inverse of it. How i tested it # This loads a project, looks at all procedure 'definition' proccodes, parses them, then constructs a new proccode.
# When I ran this, the original proccode and the new proccode were equivalent, which means that construct_proccode works as an inverse to parse_proccode
# This also constructs a proccode in a different way at the end
from scratchattach import editor
proj = editor.Project.from_sb3("test proj.sb3")
sprite = proj.find_sprite("Sprite1")
for block in sprite.blocks.values():
if block.opcode == "procedures_prototype":
parsed = editor.parse_proc_code(block.mutation.proc_code)
unparsed = editor.construct_proccode(*parsed)
print(block.mutation.proc_code)
print(parsed)
print(unparsed)
print('-' * 10)
print(
editor.construct_proccode(
"say",
editor.ArgTypes.BOOLEAN,
editor.Argument("hey", _type=editor.ArgTypes.NUMBER_OR_TEXT.value),
"aa"
)
) |
|
alr, I didn't help much but yea lol |
ive added a build_proccode function. hopefully it works.
btw, im new to github so sorry about all unnecessary changes to files like readme where i added one line. idk how to fix it or not pull request that file but ig ill learn :p